package com.kermel.common.util;

import android.content.Context;
import android.media.Ringtone;
import android.net.Uri;
import android.provider.Settings;
import android.test.AndroidTestCase;

public class RingtoneUtilsTest extends AndroidTestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }
    
    public void testThatObtainRingtoneDoesNotThrowExceptionWhenRingtoneUriStringIsNull() {
        boolean exceptionCaught = false;
        String ringtoneUriString = null;
        
        try {
            Context context = getContext();
            RingtoneUtils.obtainRingtone(context, ringtoneUriString);
        } catch (Exception e) {
            exceptionCaught = true;
        }
        assertFalse(exceptionCaught);
    }
    
    public void testThatObtainRingtoneReturnsNonNullRingtoneWhenGivenDefaultRingtonUriString() {
        String ringtoneUriString = Settings.System.DEFAULT_RINGTONE_URI.toString();
        Context context = getContext();
        
        Ringtone ringtone = RingtoneUtils.obtainRingtone(context, ringtoneUriString);

        assertNotNull(ringtone);
    }
    
    public void testThatPromptForRingtoneSelectionDoesNotThrowExceptionWhenActivityIsNull() {
        boolean exceptionCaught = false;
        
        try {
            RingtoneUtils.promptForRingtoneSelection(null);
        } catch (Exception e) {
            exceptionCaught = true;
        }
        
        assertFalse(exceptionCaught);
    }
    
    public void testThatGetRingtoneTitleFromUriDoesNotThrowExceptionWhenRingtoneContextIsNull() {
        boolean exceptionCaught = false;
        
        try {
            Context context = null;
            Uri ringtoneUri = null;
            RingtoneUtils.getRingtoneTitleFromUri(context, ringtoneUri);
        } catch (Exception e) {
            exceptionCaught = true;
        }
        
        assertFalse(exceptionCaught);
    }
    
    public void testThatGetRingtoneTitleFromUriDoesNotThrowExceptionWhenRingtoneUriIsNull() {
        boolean exceptionCaught = false;
        
        try {
            Context context = getContext();
            Uri ringtoneUri = null;
            RingtoneUtils.getRingtoneTitleFromUri(context, ringtoneUri);
        } catch (Exception e) {
            exceptionCaught = true;
        }
        
        assertFalse(exceptionCaught);
    }
    
    public void testThatGetRingtoneTitleFromUriReturnsNonNullResult() {
        Context context = getContext();
        Uri ringtoneUri = Settings.System.DEFAULT_RINGTONE_URI;
        String title = RingtoneUtils.getRingtoneTitleFromUri(context, ringtoneUri);
        assertNotNull(title);
    }
    
}
